
//EditorWindow类无法打包,注意添加这个判断
#if UNITY_EDITOR

using UnityEngine;
using UnityEditor;
using System.Linq;

namespace PluginWD
{
    public class AddCameraComps : EditorWindow
    {
        [MenuItem("Tools/添加Camera组件")]

        public static void Open()
        {
            EditorWindow.GetWindow(typeof(AddCameraComps));
        }
        void OnGUI()
        {
            if (GUILayout.Button("添加Camera组件"))
            {
                Add();
            }
        }
        public static void Add()
        {
            foreach (var t in Resources.FindObjectsOfTypeAll(typeof(Camera)).Cast<Camera>())
            {
                if (t.gameObject.name == "Main Camera")
                {
                    CameraRMS ca = t.gameObject.GetComponent<CameraRMS>();
                    if (ca == null)
                    {
                        t.gameObject.AddComponent<CameraRMS>();
                    }

                    HighlightingEffect he = t.gameObject.GetComponent<HighlightingEffect>();
                    if (he == null)
                    {
                        t.gameObject.AddComponent<HighlightingEffect>();
                    }
                    EditorUtility.SetDirty(t);
                    Debug.Log(t.gameObject.name);
                }
            }
        }
    }
}

#endif